//
//  YSAccountItemFrame.m
//  Yueshi
//
//  Created by Northwan on 15/7/30.
//  Copyright (c) 2015年 悦食中国. All rights reserved.
//

#import "YSAccountCenterItemFrame.h"

@implementation YSAccountCenterItemFrame

-(void)setProduct:(YSCartProduct *)product{
    _product = product;
    
    self.iconFrame = CGRectMake(YSPublicXInset , 15, ICON_HEIGHT, ICON_HEIGHT);
    CGSize nameSize = CGSizeZero;
    CGFloat nameX = CGRectGetMaxX(self.iconFrame)+15;
    NSString *prodName = nil;
    if(product.isPresent){
        prodName = [NSString stringWithFormat:@"(赠)%@",product.prodName];
    }else if(product.prodPromotion && product.prodPromotion.price){//抢购
        if(product.prodPromotion.isPanicBuy){
            prodName = [NSString stringWithFormat:@"(抢)%@",product.prodName];
        }
    }else{
        prodName = product.prodName;
    }
    nameSize = [prodName sizeWithFont:SYS_FONT(NAME_FONT)constrainedToSize:CGSizeMake(SCREENW-CGRectGetMaxX(self.iconFrame)-30, [UIFont systemFontOfSize:NAME_FONT].lineHeight * 4)];
    self.nameFrame = (CGRect){{nameX, 15}, nameSize};
    
    CGSize colorSize = [product.prodBuyLink sizeWithFont:SYS_FONT(SUB_FONT)];
    self.colorFrame = CGRectMake(nameX, CGRectGetMaxY(self.nameFrame)+8, colorSize.width, colorSize.height);
    
    CGSize newPriceSize = CGSizeZero;
    CGFloat newPrice = 0;
    if(product.prodPromotion&&product.prodPromotion.price){//抢购
        newPrice = product.prodPromotion.price;
    }else{
        newPrice = product.prodNewPrice;
    }
    newPriceSize = [[NSString stringWithFormat:@"¥%.1f",newPrice] sizeWithFont:SYS_FONT(NEWPRICE_FONT)];
    self.newPriceFrame = CGRectMake(nameX, CGRectGetMaxY(self.iconFrame)-NEWPRICE_FONT, newPriceSize.width, NEWPRICE_FONT);
    
    CGSize numSize = [[NSString stringWithFormat:@"x%ld",product.prodCount] sizeWithFont:SYS_FONT(NUM_FONT)];
        self.numFrame = CGRectMake(CGRectGetMaxX(self.newPriceFrame)+15, CGRectGetMaxY(self.iconFrame)-NUM_FONT, numSize.width, numSize.width);

    self.cellHeight = CGRectGetMaxY(self.iconFrame)+15;
    
    self.frame = CGRectMake(0, 0, SCREENW,self.cellHeight);
}

@end
